<?php
/**
 * Created by PhpStorm.
 * User: admin
 * Date: 2017/12/7
 * Time: 11:06
 */

namespace iBrand\Shop\Server\Controllers\V2;

use iBrand\Common\Controllers\Controller;
use Carbon\Carbon;
use iBrand\Component\Order\Models\Adjustment;
use iBrand\Component\Order\Models\Order;
use iBrand\Component\Point\Model\Point;
use iBrand\Component\Point\Repository\PointRepository;
use iBrand\Shop\Core\Models\OrderRefundRelation;
use iBrand\Shop\Core\Models\Refund;
use iBrand\Shop\Core\Models\RefundPayment;
use iBrand\Shop\Core\Repositories\OrderRepository;


class PrintController extends Controller
{

    protected $orderRepository;
    protected $pointRepository;

    public function __construct(OrderRepository $orderRepository,
                                PointRepository $pointRepository)
    {
        $this->orderRepository = $orderRepository;
        $this->pointRepository = $pointRepository;
    }

    public function index()
    {
        $order_no = request('order_no');
        if (!$order_no || !$order = $this->orderRepository->getOrderByNo($order_no)) {
            return $this->response()->errorBadRequest('订单不存在');
        }

        $bank = '          ';
        $line = '---------------------------------------';
        $hexLine = $this->str2hex($line);
        $hexBank = $this->str2hex($bank);

        /*$logo = $this->draw2PxPoint(public_path('uploads/mier2.jpg'));
        $print_data['logo'] = $logo;*/

        $shop = $order->shopOrder->shop;

        $title = '店铺名称:' . $shop->name;
        $address = '地  址:' . $shop->address;
        $phone = '';
        /*$phone = '电  话:' . $shop->phone;
        $tips = '微信扫描二维码米尔童装公众号,了解最新信息';*/
        $tips = ' ';

        $hexTitle = $this->str2hex($title, true);
        $hexAddress = $this->str2hex($address, true);
        $hexPhone = $this->str2hex($phone, true);
        //$hexTips = $this->str2hex($tips, true);

        /*小票头*/
        $print_head = [
            'title' => $hexTitle,
            'address' => $hexAddress,
            'phone' => $hexPhone,
            //'tips' => $hexTips,
            'line' => $hexLine
        ];

        /*订单头信息*/
        $order_no = '订单编号:' . $order->order_no;
        $time = '交易时间:' . $order->created_at;
        $guide = '导购:' . $order->shopOrder->clerk->name . '          收银员:' . $order->shopOrder->clerk->name;
        $hexOrder_no = $this->str2hex($order_no);
        $hexTime = $this->str2hex($time);
        $hexGuide = $this->str2hex($guide);
        $print_order_head = [
            'order_no' => $hexOrder_no,
            'time' => $hexTime,
            'guide' => $hexGuide,
            'bank' => $hexBank,
            'bank_1' => $hexBank
        ];

        /*订单商品信息*/
        /*$sku = 'GTS98112            x 2      199.00';
        $goods_name = '米尔童装春季女童T恤';
        $hexSku = $this->str2hex($sku);
        $hexGoods_name = $this->str2hex($goods_name);*/
        foreach ($order->items as $key => $item) {
            $sku = $item->item_sku . '            x ' . $item->quantity . '      ' . $item->units_total_yuan . '      ' . $item->total_yuan;
            $goods_name = $item->item_name . '(' . $item->item_meta['specs_text'] . ')';
            $hexSku = $this->str2hex($sku);
            $hexGoods_name = $this->str2hex($goods_name);
            $print_goods['sku_' . $key] = $hexSku;
            $print_goods['goods_name_' . $key] = $hexGoods_name;
        }
        $print_goods['line2'] = $hexLine;


        /*订单金额*/
        $pointDiscount = Adjustment::where('order_id', $order->id)->where('type', 'order_point_discount')->first();
        $pointDiscountAmount = 0.00;
        $point_discount_f = 0;
        if ($pointDiscount) {
            $point_discount_f = $pointDiscount->amount;
            $pointDiscountAmount = number_format($pointDiscount->amount / 100, 2, '.', "");
        }

        //新人礼优惠
        $newDiscount = Adjustment::where('order_id', $order->id)->where('type', 'order_new_user_gift')->first();
        $newDiscountAmount = 0.00;
        $new_discount_f = 0;
        if ($newDiscount) {
            $new_discount_f = $newDiscount->amount;
            $newDiscountAmount = number_format($newDiscount->amount / 100, 2, '.', "");
        }

        //双十一优惠
        $doubleDiscount = Adjustment::where('order_id', $order->id)->where('type', 'order_double_ele')->first();
        $doubleDiscountAmount = 0.00;
        $double_discount_f = 0;
        if ($doubleDiscount) {
            $double_discount_f = $doubleDiscount->amount;
            $doubleDiscountAmount = number_format($doubleDiscount->amount / 100, 2, '.', "");
        }

        $otherDiscount = number_format(($order->adjustments_total - $point_discount_f - $new_discount_f - $double_discount_f) / 100, 2, '.', "");

        $paymentDetail = $order->paymentDetail;
        $total_title = '数量              x ' . $order->count;
        $total_amount = '*商品金额                  ' . $order->items_total_yuan;
        $point_discount_amount = '*积分抵扣金额               ' . $pointDiscountAmount;
        $new_discount_amount = '*新人优惠金额               ' . $newDiscountAmount;
        $double_discount_amount = '*双十一优惠金额              ' . $doubleDiscountAmount;
        $discount_amount = '*其他优惠金额               ' . $otherDiscount;
        $receivable_amount = '*应收金额                  ' . $order->total_yuan;
        $actual_amount = '*实收金额                  ' . number_format($paymentDetail->actual / 100, 2, '.', "");
        $remaining_amount = '*找零金额                  ' . number_format($paymentDetail->remaining / 100, 2, ".", "");
        $hexTotal_title = $this->str2hex($total_title, '');
        $hexTotal_amount = $this->str2hex($total_amount);
        $hexPointDiscount_amount = $this->str2hex($point_discount_amount);
        $hexNewDiscount_amount = $this->str2hex($new_discount_amount);
        $hexDoubleDiscount_amount = $this->str2hex($double_discount_amount);
        $hexDiscount_amount = $this->str2hex($discount_amount);
        $hexReceivable_amount = $this->str2hex($receivable_amount);
        $hexActual_amount = $this->str2hex($actual_amount);
        $hexRemaining_amount = $this->str2hex($remaining_amount);
        $print_amount = [
            'total_title' => $hexTotal_title,
            'total_amount' => $hexTotal_amount,
            'discount_amount' => $hexDiscount_amount,
            'point_discount_amount' => $hexPointDiscount_amount,
            'new_discount_amount' => $hexNewDiscount_amount,
            'double_discount_amount' => $hexDoubleDiscount_amount,
            'receivable_amount' => $hexReceivable_amount,
            'actual_amount' => $hexActual_amount,
            'remaining_amount' => $hexRemaining_amount,
            'line3' => $hexLine
        ];

        if (!$newDiscount) {
            unset($print_amount['new_discount_amount']);
        }
        if (!$doubleDiscount) {
            unset($print_amount['double_discount_amount']);
        }

        /*总计*/
        $pay_total_title = ' TOTAL 总计                       ' . $order->total_yuan;
        $pay_title = '支付方式              金额';


        //$pay_total = '合计                ￥' . $order->total_yuan . '         00.00';

        $item_ids = $order->items->pluck('id')->toArray();
        $point = Point::where(['action' => 'order_item'])->whereIn('item_id', $item_ids)->get()->sum('value');

        $mobile = str_contains($order->user->mobile, '99999999') ? '默认会员' : substr_replace($order->user->mobile, '****', 3, 4);
        $user = '会员                              ' . $mobile;
        $get_point = '本次获得积分                        ' . $point;
        $total_point = '累计积分                            ' . $this->pointRepository->getSumPointValid($order->user_id);


        $hexPay_total_title = $this->str2hex($pay_total_title, false, true);
        $hexPay_title = $this->str2hex($pay_title);
        //$hexPay_total = $this->str2hex($pay_total);

        $hexUser = $this->str2hex($user);
        $hexGet_point = $this->str2hex($get_point);
        $hexTotal_point = $this->str2hex($total_point);
        $print_total = [
            'pay_total_title' => $hexPay_total_title,
            'bank2' => $hexBank,
            'pay_title' => $hexPay_title
        ];

        foreach ($order->payments as $key => $item) {
            $pay_method = $item->channel_text . '                ￥' . $item->amount_yuan;
            $print_total['pay_method_' . $key] = $this->str2hex($pay_method);
        }

        //$print_total['pay_total'] = $hexPay_total;
        $print_total['bank3'] = $hexBank;

        if (!str_contains($order->user->mobile, '99999999')) {  //如果是默认会员，不打印会员信息
            $print_total['user'] = $hexUser;
            $print_total['get_point'] = $hexGet_point;
            $print_total['total_point'] = $hexTotal_point;
        }


        /*结束语*/
        $end_note = '* * * 谢谢惠顾 * * *';
        $end_1 = '1.小票是您消费的唯一凭证，请妥善保存';
        $end_2 = '2.7天内可凭有效票据及原始吊牌退换货';
        $end_3 = '3.如发生退货，赠品退回';
        $end_4 = '4.袜子/内裤一经售出，概不退换';
        $end_5 = '关爱至上 真心服务';

        $hexEnd_note = $this->str2hex($end_note, true, true);
        $hexEnd_1 = $this->str2hex($end_1);
        $hexEnd_2 = $this->str2hex($end_2);
        $hexEnd_3 = $this->str2hex($end_3);
        $hexEnd_4 = $this->str2hex($end_4);
        $hexEnd_5 = $this->str2hex($end_5, true, true);
        /*$qrcode = $this->draw2PxPoint(public_path('uploads/mier-qrcode.jpg'));*/
        $print_end = [
            'bank4' => $hexBank,
            'end_note' => $hexEnd_note,
            'end_1' => $hexEnd_1,
            'end_2' => $hexEnd_2,
            'end_3' => $hexEnd_3,
            'end_4' => $hexEnd_4,
            'end_5' => $hexEnd_5,
            'bank5' => $hexBank,
            'bank6' => $hexBank,
            'bank7' => $hexBank,
            'bank8' => $hexBank,
            'bank9' => $hexBank
            /*'bank10' => $hexBank,
           'bank11' => $hexBank,
           'bank12' => $hexBank
          'qrcode' => $qrcode*/
        ];

        $c = ['qie' => ['0a', '1D', '56', '1', '0']];

        $print_data = array_merge($print_head, $print_order_head, $print_goods, $print_amount, $print_total, $print_end, $c);

        return $this->success($print_data);
    }


    public function img2Base64()
    {
        $img_base64 = '';

        $app_img_file = public_path('uploads/1.bmp');

        $img_info = getimagesize($app_img_file);

        $fp = fopen($app_img_file, "r");     //图片是否可读权限

        if ($fp) {

            $file_content = chunk_split(base64_encode(fread($fp, filesize($app_img_file))));//base64编码


            $img_base64 = 'data:image/' . 'bmp' . ';base64,' . $file_content;//合成图片的base64编码

            fclose($fp);


        }
        return $img_base64;
    }

    /**
     * 获取小程序post过来的二维码数据
     */
    public function qrcodeData()
    {
        $data = request('qrcodeArray');
        \Log::info($data);
        $qrcode = [];
        foreach ($data as $item) {
            $qrcode = array_merge($qrcode, $item);
        }
        $expiresAt = Carbon::now()->addMinutes(30);

        cache()->put('print_qrcode', $qrcode, $expiresAt);
    }

    /**
     * 获取打印的二维码数据
     */
    public function getQrcodeData()
    {
        $data = cache()->get('print_qrcode');
        return $data;
    }


    public function convertCode()
    {
        return response(['B1B1', 'BEA9', 'BBB6', 'D3AD', 'C4FA'])->header('Content-Type', 'text/html;charset=GBK');
    }

    public function strtoascii($str)
    {
        $str = mb_convert_encoding($str, 'GB2312');
        $change_after = '';
        for ($i = 0; $i < strlen($str); $i++) {
            $temp_str = dechex(ord($str[$i]));
            $change_after .= $temp_str[1] . $temp_str[0];
        }
        return strtoupper($change_after);
    }


    /*function str2hex($str)
    {
        $hex = [];
        for ($i = 0, $length = mb_strlen($str); $i < $length; $i++) {
            $hex [] = dechex(ord($str{$i}));
        }
        return $hex;
    }*/

    public function str2hex16($string)
    {
        $length = strlen($string);

        $result = array();
//十进制
        for ($i = 0; $i < $length; $i++) {
            if (ord($string[$i]) > 127) {
                $result[] = ord($string[$i]) . ' ' . ord($string[++$i]);
            }
        }
//十六进制
        $strings = array();
        foreach ($result as $v) {
            $dec = explode(" ", $v);
            $strings[] = dechex($dec[0]) . " " . dechex($dec[1]);
        }

        return $strings;
    }

    function urlstr($str)
    {
        $url = "";
        $m1 = "";
        for ($i = 0; $i <= strlen($str); $i++) {
            $m1 = base_convert(ord(substr($str, $i, 1)), 10, 16);
            if ($m1 != "0")
                $url = $url . " " . $m1;
        }
        return $url;
    }

    /**
     * 灰度图片
     * @param $x
     * @param $y
     * @param $bit
     *
     */
    public function px2Byte($x, $y, $file)
    {
        $image = 'image.jpg';
        // Supports http if allow_url_fopen is enabled
//        $image = file_get_contents($file);
//        $img = imagecreatefromstring($image);
        $img = $file;
        $width = imagesx($img);
        $height = imagesy($img);

        if ($x < $width AND $y < $height) {
            $rgb = imagecolorat($img, $x, $y);
            //     dd('rgb'.$rgb);
            $a = ($rgb >> 24) & 0xFF;
            $r = ($rgb >> 16) & 0xFF;
            $g = ($rgb >> 8) & 0xFF;
            $b = $rgb & 0xFF;

            $a = abs(($a / 127) - 1);
            $grey = $this->RGB2Gray($r, $g, $b);
            if ($grey < 128) {
                $b = 1;
            } else {
                $b = 0;
            }
            return $b;
        }
        return 0;

    }

    /**
     * 图片灰度的转化
     */
    private function RGB2Gray($r, $g, $b)
    {
        $gray = (int)(0.29900 * $r + 0.58700 * $g + 0.11400 * $b);  //灰度转化公式
        return $gray;
    }

    /*************************************************************************
     * 假设一个240*240的图片，分辨率设为24, 共分10行打印
     * 每一行,是一个 240*24 的点阵, 每一列有24个点,存储在3个byte里面。
     * 每个byte存储8个像素点信息。因为只有黑白两色，所以对应为1的位是黑色，对应为0的位是白色
     **************************************************************************/
    /**
     * 把一张Bitmap图片转化为打印机可以打印的字节流
     *
     * @param bmp
     * @return
     */
    public function draw2PxPoint($file)
    {
        //用来存储转换后的 bitmap 数据。为什么要再加1000，这是为了应对当图片高度无法
        //整除24时的情况。比如bitmap 分辨率为 240 * 250，占用 7500 byte，
        //但是实际上要存储11行数据，每一行需要 24 * 240 / 8 =720byte 的空间。再加上一些指令存储的开销，
        //所以多申请 1000byte 的空间是稳妥的，不然运行时会抛出数组访问越界的异常。
        //$file = public_path('uploads/mier.jpg');
        $image = file_get_contents($file);


        $img = imagecreatefromstring($image);
        $width = imagesx($img);
        $height = imagesy($img);

        $size = $width * $height / 8 + 1000;
        $data = [];

        $k = 0;
        //设置行距为0的指令
//        $data[$k++] = '0x1B';
//        $data[$k++] = '0x33';
//        $data[$k++] = '0x00';

        //居中
//        $data[$k++] = 27;
//        $data[$k++] = 97;
//        $data[$k++] = 1;

        $data[$k++] = 27;
        $data[$k++] = 51;
        $data[$k++] = 0;


        // 逐行打印
        for ($j = 0; $j < ($height / 24); $j++) {

            //打印图片的指令
//            $data[$k++] = '0x1B';
//            $data[$k++] = '0x2A';
            $data[$k++] = 27;
            $data[$k++] = 42;
            $data[$k++] = 33;
            $data[$k++] = $width % 256 & 0xff; //nL
            $data[$k++] = $width / 256 & 0xff; //nH

            //对于每一行，逐列打印
            for ($i = 0; $i < $height; $i++) {
                //每一列24个像素点，分为3个字节存储
                for ($m = 0; $m < 3; $m++) {
                    $data[$k] = 0;
                    //每个字节表示8个像素点，0表示白色，1表示黑色
                    for ($n = 0; $n < 8; $n++) {
                        $b = $this->px2Byte($i, $j * 24 + $m * 8 + $n, $img);
                        $data[$k] += ($data[$k] + $b) & 0xff;

                    }
                    $k++;
                }
            }
//            $data[$k++] = 10;//换行
            //  break;
        }

        $data[] = 10;
//
//        $data[] = 27;
//        $data[] = 97;
//        $data[] = 0;

        $data[] = 27;
        $data[] = 50;

        return $data;
    }


    private function str2hex($str, $center = false, $bold = false)
    {
        $str = iconv('utf-8', 'gbk', $str);
        $hex = '';

        for ($i = 0, $length = strlen($str); $i < $length; $i++) {
            $hex .= dechex(ord($str{$i}));
        }

        //$array = ['20', '20', '20', '20'];

        /*添加样式*/
        if ($center) {  //居中
            $array[] = '1B';
            $array[] = '61';
            $array[] = '1';
        }

        if ($bold) {  //字体放大
            $array[] = '1B';
            $array[] = '21';
            $array[] = '18';
        }
        /*end添加样式*/

        for ($start = 0; $start < strlen($hex); $start += 2) {
            $array[] = substr($hex, $start, 2);
        }

        /*取消样式*/
        if ($bold) {  //字体放大
            $array[] = '1B';
            $array[] = '21';
            $array[] = '0';
        }

        $array[] = '0a';
        if ($center) {  //居中
            $array[] = '1B';
            $array[] = '61';
            $array[] = '0';

        }
        /*end取消样式*/

        return $array;
    }

    public function refund()
    {
        $refund_id = request('refund_id');
        if (!$refund = Refund::find($refund_id)) {
            return $this->failed('售后不存在');
        }

        $bank = '          ';
        $line = '---------------------------------------';
        $hexLine = $this->str2hex($line);
        $hexBank = $this->str2hex($bank);

        $shop = $refund->shop;

        $title = '店铺名称:' . $shop->name;
        $address = '地  址:' . $shop->address;
        $phone = '';
        $tips = ' ';

        $hexTitle = $this->str2hex($title, true);
        $hexAddress = $this->str2hex($address, true);
        $hexPhone = $this->str2hex($phone, true);
        $hexTips = $this->str2hex($tips, true);

        /*小票头*/
        $print_head = [
            'title' => $hexTitle,
            'address' => $hexAddress,
            'phone' => $hexPhone,
            'tips' => $hexTips,
            'line' => $hexLine
        ];

        /*订单头信息*/
        $order_no = '售后编号:' . $refund->refund_no;
        $time = '售后时间:' . $refund->created_at;

        $refundType = $refund->type == 1 ? '退货' : '换货';
        $type = '售后类型：' . $refundType;

        $guide = '导购:' . $refund->clerk->name;
        $hexOrder_no = $this->str2hex($order_no);
        $hexTime = $this->str2hex($time);
        $hexType = $this->str2hex($type);
        $hexGuide = $this->str2hex($guide);
        $print_order_head = [
            'order_no' => $hexOrder_no,
            'time' => $hexTime,
            'type' => $hexType,
            'guide' => $hexGuide,
            'bank' => $hexBank,
            'bank_1' => $hexBank
        ];

        /*售后商品*/
        $print_goods['refund_title'] = $this->str2hex('退：', false, true);
        foreach ($refund->items as $key => $item) {
            $orderItem = $item->orderItem;
            $sku = $orderItem->item_sku . '            x ' . $item->quantity . '      ' . $item->amount / 100;
            $goods_name = $orderItem->item_name . '(' . $orderItem->item_meta['specs_text'] . ')';
            $hexSku = $this->str2hex($sku);
            $hexGoods_name = $this->str2hex($goods_name);
            $print_goods['sku_' . $key] = $hexSku;
            $print_goods['goods_name_' . $key] = $hexGoods_name;
        }
        $print_goods['line2'] = $hexLine;

        /*换货商品*/
        $print_refund_goods['bank'] = $hexBank;
        if ($refund->type == 2) {
            $relation = OrderRefundRelation::where('refund_id', $refund_id)->first();
            $refundOrder = Order::find($relation->order_id);

            $print_refund_goods['exchange_title'] = $this->str2hex('换：', false, true);
            foreach ($refundOrder->items as $key => $item) {
                $sku = $item->item_sku . '            x ' . $item->quantity . '      ' . $item->units_total_yuan;
                $goods_name = $item->item_name . '(' . $item->item_meta['specs_text'] . ')';
                $hexSku = $this->str2hex($sku);
                $hexGoods_name = $this->str2hex($goods_name);
                $print_refund_goods['exchange_sku_' . $key] = $hexSku;
                $print_refund_goods['exchange_goods_name_' . $key] = $hexGoods_name;
            }
            $print_refund_goods['line3'] = $hexLine;
        }

        /*金额展示*/
        $refundPayment = RefundPayment::where('refund_id', $refund_id)->where('origin_type', '<>', 'order')->first();
        if ($refundPayment) {
            $refund_amount = '*退款金额                  ' . number_format($refundPayment->amount / 100, 2, ".", "");
            $refund_channel = '*退款方式                  ' . $refundPayment->origin_type_text;
            $hexRefundAmount = $this->str2hex($refund_amount);
            $hexRefundChannel = $this->str2hex($refund_channel);
            $print_amount = [
                'refund_amount' => $hexRefundAmount,
                'refund_channel' => $hexRefundChannel
            ];
        } elseif ($orderRefund = OrderRefundRelation::where('refund_id', $refund_id)->where('difference_amount', 0)->first()) {  //退款金额为0
            $refund_amount = '*退款金额                  0.00';
            $hexRefundAmount = $this->str2hex($refund_amount);
            $print_amount = [
                'refund_amount' => $hexRefundAmount
            ];
        }


        if ($refund->type == 2 AND
            $orderRefund = OrderRefundRelation::where('refund_id', $refund_id)->where('difference_amount', '<', 0)->first()
        ) {  // 需要补款

            $order = Order::find($orderRefund->order_id);
            $paymentDetail = $order->paymentDetail;
            $diffAmount = number_format((-$orderRefund->difference_amount - $paymentDetail->wipe) / 100, 2, '.', "");

            $total_title = '数量              x ' . $order->count;
            $total_amount = '*商品金额                  ' . $order->items_total_yuan;
            $discount_amount = '*优惠金额                  ' . $order->adjustments_total_yuan;
            $receivable_amount = '*订单金额                  ' . $order->total_yuan;
            $refund_amount = '*退款金额                  ' . number_format(-$refund->amount / 100, 2, '.', "");
            $diff_amount = '*补款金额                  ' . $diffAmount;
            $actual_amount = '*实收金额                  ' . number_format($paymentDetail->actual / 100, 2, '.', "");
            $remaining_amount = '*找零金额                  ' . number_format($paymentDetail->remaining / 100, 2, '.', "");
            $hexTotal_title = $this->str2hex($total_title, '');
            $hexTotal_amount = $this->str2hex($total_amount);
            $hexDiscount_amount = $this->str2hex($discount_amount);
            $hexReceivable_amount = $this->str2hex($receivable_amount);
            $hexRefundAmount = $this->str2hex($refund_amount);
            $hexActual_amount = $this->str2hex($actual_amount);
            $hexRemaining_amount = $this->str2hex($remaining_amount);
            $hexDiffAmount = $this->str2hex($diff_amount);

            $print_amount = [
                'total_title' => $hexTotal_title,
                'total_amount' => $hexTotal_amount,
                'discount_amount' => $hexDiscount_amount,
                'receivable_amount' => $hexReceivable_amount,
                'refund_amount' => $hexRefundAmount,
                'diff_amount' => $hexDiffAmount,
                'actual_amount' => $hexActual_amount,
                'remaining_amount' => $hexRemaining_amount,
                'line4' => $hexLine
            ];


            $pay_title = '支付方式              金额';
            $hexPay_title = $this->str2hex($pay_title);

            $print_amount['pay_title'] = $hexPay_title;

            foreach ($order->payments as $key => $item) {
                if ($item->channel != 'refund_amount') {
                    $pay_method = $item->channel_text . '                ￥' . $item->amount_yuan;
                    $print_amount['pay_method_' . $key] = $this->str2hex($pay_method);
                }
            }

        }


        /*结束语*/
        $end_note = '* * * 谢谢惠顾 * * *';
        $end_1 = '1.小票是您消费的唯一凭证，请妥善保存';
        $end_2 = '2.已换货商品不可进行二次退换货';
        $end_4 = '3.袜子/内裤一经售出，概不退换';
        $end_5 = '关爱至上 真心服务';

        $hexEnd_note = $this->str2hex($end_note, true, true);
        $hexEnd_1 = $this->str2hex($end_1);
        $hexEnd_2 = $this->str2hex($end_2);
        $hexEnd_4 = $this->str2hex($end_4);
        $hexEnd_5 = $this->str2hex($end_5, true, true);
        $print_end = [
            'bank4' => $hexBank,
            'end_note' => $hexEnd_note,
            'end_1' => $hexEnd_1,
            'end_2' => $hexEnd_2,
            'end_4' => $hexEnd_4,
            'end_5' => $hexEnd_5,
            'bank5' => $hexBank,
            'bank6' => $hexBank,
            'bank7' => $hexBank,
            'bank8' => $hexBank,
            'bank9' => $hexBank
            /*'bank10' => $hexBank,
            'bank11' => $hexBank,
            'bank12' => $hexBank*/
        ];
        $c = ['qie' => ['0a', '1D', '56', '1', '0']];

        $print_data = array_merge($print_head, $print_order_head, $print_goods, $print_refund_goods, $print_amount, $print_end, $c);

        return $this->success($print_data);

    }

}